| Conditions | 1 | 
| Paths | 64 | 
| Total Lines | 149 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | define(['snabbdom', 'helper', 'moment'], function (V, helper, moment) { | 
            ||
| 2 | 'use strict';  | 
            ||
| 3 | V = V.default;  | 
            ||
| 4 | |||
| 5 |   var self = {}; | 
            ||
| 6 | |||
| 7 |   function showBar(v, width, warning) { | 
            ||
| 8 |     return V.h('span', | 
            ||
| 9 |       { props: { className: 'bar' + (warning ? ' warning' : '') } }, | 
            ||
| 10 | [  | 
            ||
| 11 |         V.h('span', | 
            ||
| 12 |           { | 
            ||
| 13 |             style: { width: (width * 100) + '%' } | 
            ||
| 14 | }),  | 
            ||
| 15 |         V.h('label', v) | 
            ||
| 16 | ]  | 
            ||
| 17 | );  | 
            ||
| 18 | }  | 
            ||
| 19 | |||
| 20 |   self.showStatus = function showStatus(d) { | 
            ||
| 21 |     return V.h('td', | 
            ||
| 22 |       { props: { className: d.is_online ? 'online' : 'offline' } }, | 
            ||
| 23 |       _.t((d.is_online ? 'node.lastOnline' : 'node.lastOffline'), { | 
            ||
| 24 | time: d.lastseen.fromNow(),  | 
            ||
| 25 |         date: d.lastseen.format('DD.MM.YYYY, H:mm:ss') | 
            ||
| 26 | }));  | 
            ||
| 27 | };  | 
            ||
| 28 | |||
| 29 |   self.showGeoURI = function showGeoURI(d) { | 
            ||
| 30 |     if (!helper.hasLocation(d)) { | 
            ||
| 31 | return undefined;  | 
            ||
| 32 | }  | 
            ||
| 33 | |||
| 34 |     return V.h('td', | 
            ||
| 35 |       V.h('a', | 
            ||
| 36 |         { props: { href: 'geo:' + d.location.latitude + ',' + d.location.longitude } }, | 
            ||
| 37 | Number(d.location.latitude.toFixed(6)) + ', ' + Number(d.location.longitude.toFixed(6))  | 
            ||
| 38 | )  | 
            ||
| 39 | );  | 
            ||
| 40 | };  | 
            ||
| 41 | |||
| 42 |   self.showGateway = function showGateway(d) { | 
            ||
| 43 |     return d.is_gateway ? _.t('yes') : undefined; | 
            ||
| 44 | };  | 
            ||
| 45 | |||
| 46 |   self.showFirmware = function showFirmware(d) { | 
            ||
| 47 | return [  | 
            ||
| 48 | helper.dictGet(d, ['firmware', 'release']),  | 
            ||
| 49 | helper.dictGet(d, ['firmware', 'base'])  | 
            ||
| 50 |     ].filter(function (n) { | 
            ||
| 51 | return n !== null;  | 
            ||
| 52 |     }).join(' / ') || undefined; | 
            ||
| 53 | };  | 
            ||
| 54 | |||
| 55 |   self.showUptime = function showUptime(d) { | 
            ||
| 56 | return moment.utc(d.uptime).local().fromNow(true);  | 
            ||
| 57 | };  | 
            ||
| 58 | |||
| 59 |   self.showFirstSeen = function showFirstSeen(d) { | 
            ||
| 60 | return d.firstseen.fromNow(true);  | 
            ||
| 61 | };  | 
            ||
| 62 | |||
| 63 |   self.showLoad = function showLoad(d) { | 
            ||
| 64 |     if (!d.loadavg) { | 
            ||
| 65 | return undefined;  | 
            ||
| 66 | }  | 
            ||
| 67 | return showBar(d.loadavg.toFixed(2), d.loadavg % 1, d.loadavg >= d.nproc);  | 
            ||
| 68 | };  | 
            ||
| 69 | |||
| 70 |   self.showRAM = function showRAM(d) { | 
            ||
| 71 |     if (!d.memory_usage) { | 
            ||
| 72 | return undefined;  | 
            ||
| 73 | }  | 
            ||
| 74 | return showBar(Math.round(d.memory_usage * 100) + ' %', d.memory_usage, d.memory_usage >= 0.8);  | 
            ||
| 75 | };  | 
            ||
| 76 | |||
| 77 |   self.showSite = function showSite(d) { | 
            ||
| 78 | var rt = d.site_code;  | 
            ||
| 79 |     if (config.siteNames) { | 
            ||
| 80 |       config.siteNames.forEach(function (t) { | 
            ||
| 81 |         if (d.site_code === t.site) { | 
            ||
| 82 | rt = t.name;  | 
            ||
| 83 | }  | 
            ||
| 84 | });  | 
            ||
| 85 | }  | 
            ||
| 86 | return rt;  | 
            ||
| 87 | };  | 
            ||
| 88 | |||
| 89 |   self.showClients = function showClients(d) { | 
            ||
| 90 |     if (!d.is_online) { | 
            ||
| 91 | return undefined;  | 
            ||
| 92 | }  | 
            ||
| 93 | |||
| 94 | var clients = [  | 
            ||
| 95 |       V.h('span', [ | 
            ||
| 96 |         d.clients > 0 ? d.clients : _.t('none'), | 
            ||
| 97 |         V.h('br'), | 
            ||
| 98 |         V.h('i', { props: { className: 'ion-people', title: _.t('node.clients') } }) | 
            ||
| 99 | ]),  | 
            ||
| 100 |       V.h('span', | 
            ||
| 101 |         { props: { className: 'legend-24ghz' } }, | 
            ||
| 102 | [  | 
            ||
| 103 | d.clients_wifi24,  | 
            ||
| 104 |           V.h('br'), | 
            ||
| 105 |           V.h('span', { props: { className: 'symbol', title: '2,4 Ghz' } }) | 
            ||
| 106 | ]),  | 
            ||
| 107 |       V.h('span', | 
            ||
| 108 |         { props: { className: 'legend-5ghz' } }, | 
            ||
| 109 | [  | 
            ||
| 110 | d.clients_wifi5,  | 
            ||
| 111 |           V.h('br'), | 
            ||
| 112 |           V.h('span', { props: { className: 'symbol', title: '5 Ghz' } }) | 
            ||
| 113 | ]),  | 
            ||
| 114 |       V.h('span', | 
            ||
| 115 |         { props: { className: 'legend-others' } }, | 
            ||
| 116 | [  | 
            ||
| 117 | d.clients_other,  | 
            ||
| 118 |           V.h('br'), | 
            ||
| 119 |           V.h('span', { props: { className: 'symbol', title: _.t('others') } }) | 
            ||
| 120 | ])  | 
            ||
| 121 | ];  | 
            ||
| 122 | |||
| 123 |     return V.h('td', { props: { className: 'clients' } }, clients); | 
            ||
| 124 | };  | 
            ||
| 125 | |||
| 126 |   self.showIPs = function showIPs(d) { | 
            ||
| 127 | var string = [];  | 
            ||
| 128 | var ips = d.network.addresses;  | 
            ||
| 129 | ips.sort();  | 
            ||
| 130 |     ips.forEach(function (ip, i) { | 
            ||
| 131 |       if (i > 0) { | 
            ||
| 132 |         string.push(V.h('br')); | 
            ||
| 133 | }  | 
            ||
| 134 | |||
| 135 |       if (ip.indexOf('fe80:') !== 0) { | 
            ||
| 136 |         string.push(V.h('a', { props: { href: 'http://[' + ip + ']/', target: '_blank' } }, ip)); | 
            ||
| 137 |       } else { | 
            ||
| 138 | string.push(ip);  | 
            ||
| 139 | }  | 
            ||
| 140 | });  | 
            ||
| 141 |     return V.h('td', string); | 
            ||
| 142 | };  | 
            ||
| 143 | |||
| 144 |   self.showAutoupdate = function showAutoupdate(d) { | 
            ||
| 145 |     return d.autoupdater.enabled ? _.t('node.activated', { branch: d.autoupdater.branch }) : _.t('node.deactivated'); | 
            ||
| 146 | };  | 
            ||
| 147 | |||
| 148 | return self;  | 
            ||
| 149 | });  | 
            ||
| 150 |